/***********************************************
 This file is part of redia-bapps-main-ios.
 
 Copyright (c) 2015 Redia A/S
 
 Redia-bapps-main-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Redia-bapps-main-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-bapps-main-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */

//
//  BappsSearchResult.m
//  bapps
//
//  Created by Nikolaj Tørring on 8/2/13.
//  Copyright (c) 2013 redia. All rights reserved.
//

#import "BARecord.h"
#import "JSONEncodingHelperMethods.h"

@implementation BARecord

+ (id)objectWithJSONObject:(NSDictionary *)jsonObj
{
    BARecord *obj = [BARecord new];
    
    obj.title = [JSONEncodingHelperMethods parseStringWithKey:@"title" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.title);
    obj.identifier = [JSONEncodingHelperMethods parseStringWithKey:@"identifier" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.identifier);
    obj.faust = [JSONEncodingHelperMethods parseStringWithKey:@"faust" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.faust);
    
    obj.moreInSameSeries = [JSONEncodingHelperMethods parseBoolWithKey:@"moreInSameSeries" fromJsonObject:jsonObj];

    obj.isbn = [JSONEncodingHelperMethods parseStringWithKey:@"isbn" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.isbn);

    obj.shelfmark = [JSONEncodingHelperMethods parseStringWithKey:@"shelfmark" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.shelfmark);
    obj.type = [JSONEncodingHelperMethods parseStringWithKey:@"type" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.type);
    obj.creators = [JSONEncodingHelperMethods parseArrayOfStringsWithKey:@"creators" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSArray, obj.creators);
    
    obj.subjects = [JSONEncodingHelperMethods parseArrayOfStringsWithKey:@"subjects" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSArray, obj.subjects);
   
    obj.seriesInfo = [JSONEncodingHelperMethods parseStringWithKey:@"seriesInfo" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.seriesInfo);
    
    obj.isERessource = [JSONEncodingHelperMethods parseBoolWithKey:@"isERessource" fromJsonObject:jsonObj];
    
    return obj;
}

-(NSDictionary *)toJSONObject{
    DLog(@"Not implemented");
    return nil;
}

+ (BARecord *)recordFromFullRecord:(BAFullRecord *)fullRecord
{
    BARecord *rec = [BARecord new];
    rec.title = fullRecord.title;
    rec.identifier = fullRecord.identifier;
    rec.faust = fullRecord.faust;
    rec.moreInSameSeries = fullRecord.moreInSameSeries;
    rec.isbn = fullRecord.isbn;
    rec.shelfmark = fullRecord.shelfmark;
    rec.type = fullRecord.type;
    rec.creators = fullRecord.creators;
    rec.subjects = fullRecord.subjects;
    rec.seriesInfo = fullRecord.seriesInfo;
    rec.isERessource = fullRecord.isERessource;
    return rec;
}

@end
